#include"mqc_connection.hpp"

// //DIRECT
int main(){

    std::string ip = "127.0.0.1";
    int port = 8080;
    mq::AsyncWorker::ptr worker = std::make_shared<mq::AsyncWorker>();
    mq::ClientConnection client(ip,port,worker);
    client.connect();
    mq::ClientChannel::ptr clp = client.openChannel();

    google::protobuf::Map<std::string,std::string> gmap;
    clp->declareExchange("exchange1",mq::ExchangeType::DIRECT,true,false,gmap);
    clp->declareQueue("queue1",true,false,false,gmap);
    clp->declareQueue("queue2",true,false,false,gmap);
    clp->bind("exchange1","queue1","queue1");
    clp->bind("exchange1","queue2","news.music.#");
    for(int i = 0;i < 10;i++){
        std::string str = "hello world - " + std::to_string(i); 
        mq::BasicProperty bp;
        bp.set_id(Uuidhelper::BuideUuid());
        bp.set_deliverymod(mq::DeliveryMode::DURABLE);
        bp.set_routingkey("news.music.pop");
        int ret = clp->basicPublish("exchange1",str,&bp);
        if(ret == false) {std::cout<<"发送消息失败..."<<std::endl;}
    }
    clp->closeChannel();
    return 0;
}

// //FANOUT
// int main(){

//     std::string ip = "127.0.0.1";
//     int port = 8080;
//     mq::AsyncWorker::ptr worker = std::make_shared<mq::AsyncWorker>();
//     mq::ClientConnection client(ip,port,worker);
//     client.connect();
//     mq::ClientChannel::ptr clp = client.openChannel();

//     google::protobuf::Map<std::string,std::string> gmap;
//     clp->declareExchange("exchange1",mq::ExchangeType::FAOUT,true,false,gmap);
//     clp->declareQueue("queue1",true,false,false,gmap);
//     clp->declareQueue("queue2",true,false,false,gmap);
//     clp->bind("exchange1","queue1","queue1");
//     clp->bind("exchange1","queue2","news.music.#");
//     for(int i = 0;i < 10;i++){
//         std::string str = "hello world - " + std::to_string(i); 
//         int ret = clp->basicPublish("exchange1",str,nullptr);
//         if(ret == false) {std::cout<<"发送消息失败..."<<std::endl;}
//     }
//     clp->closeChannel();
//     return 0;
// }
